// pages/introduce/introduce.js
import routerManager from '../../utils/routerManager.js';
import http from "../../utils/http";
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    service:{},
    showPopup:false,
    fortuneteller:{}
  },
  toAtoAppoint(){
    routerManager.toAppoint(this.data.service.id,this.data.service.price,this.data.service.duration,this.data.service.name);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log("introduce onload")
    let that = this;
    const eventChannel = this.getOpenerEventChannel();
    eventChannel.on('service', function(service) {
      that.setData({
        service:service
      });
      console.log(service)
    })
    eventChannel.on('fortuneteller', function(fortuneteller) {
      that.setData({
        fortuneteller:fortuneteller
      });
      console.log(fortuneteller)
    })
  },
  
  userInfoCallback: function(event) {
    console.log("userInfoCallback",event);
    if(event.detail.errMsg == 'getUserInfo:ok'){
      let that = this;
      http.oauthLogin(event, data => {
        that.setData({
          hasUserInfo:true
        });
        that.toAtoAppoint();
      });
    }
  },
  share:function(event){
    this.setData({
      showPopup:true
    });
  },
  savePic:function(){
    let cid = app.globalData.userInfo.id;
    let serviceId = this.data.service.id;
    let fid =  this.data.fortuneteller.id;
    let path = "/pages/share-redirect/share-redicrect";
    let mode = "service";
    routerManager.toWebview(cid,serviceId,path,mode,fid);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: this.data.fortuneteller.nickname,
      desc: this.data.service.name,
      imageUrl: this.data.fortuneteller.image,
      path:"/pages/share-redirect/share-redicrect?serviceId=" + this.data.service.id + '&fid='+ this.data.fortuneteller.id
    };
  }
})
